<!DOCTYPE html>
<html>
<head>
	<title>餐饮营销支持系统</title>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<link href="../../css/bootstrap.min.css" rel="stylesheet">
	<!-- <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css"> -->
	<link rel="stylesheet" type="text/css" href="../../css/waiter.css">
	<link rel="stylesheet" type="text/css" href="../../css/news.css">
</head>
<body>
	<div id="head">
		<div class="navbar navbar-default  navbar-inverse" role="navigation">
			<div class="navbar-header">
				<a href="##" class="navbar-brand">餐饮营销支持系统</a>
			</div>
			<button type="submit" class="btn btn-danger">
				<span style="margin-right: 5px" class="glyphicon glyphicon-off"></span>注销
			</button>
		</div>

	</div>
	
	<div id="left">
		<p class="left-head">柜 台</p>

		<div class="container">
			<div class="row" style="margin-top: 0px">
				<a href="./news.html">
					<div class="col-md-12">
						<span class="glyphicon glyphicon-asterisk"></span>
						<p>结账</p>
					</div>
				</a>
			</div>
			<div class="row act">

				<div class="col-md-12">
					<span class="glyphicon glyphicon-comment"></span>
					<p>订 单</p>
				</div>

			</div>
		</div>
	</div>

	<div id="right">
		<div class="right-head">
			<ol class="breadcrumb">
				<li><a href="#">首页</a></li>
				<li class="active">订单消息</li>
			</ol> 
		</div>
		<div class="con">


			<div class="row">
				<div class="col-lg-8 col-lg-offset-2" >
					<div class="panel panel-default">
						<div class="panel-body">
							<div class="row">
								<p style="text-align: center;">订单消息</p>
							</div>
							<div class="row">
								<div class="col-lg-4 col-lg-offset-1">
									<div class="list-group">
										<a style="font-weight: 700" class="list-group-item list-group-item-success">
											桌号<span class="pull-right">处理</span>
										</a>
										<div class="list-group" id="positions">
										</div>

									</div>
								</div>
								<div class="col-lg-6">
									<div class="table-responsive">
										<table class="table table-striped table-bordered table-hover">
											<thead>
												<tr>
													<th>位置</th>
													<th>菜名</th>
													<th>份数</th>
													<th>总价</th>
													<th>状态</th>
												</tr>
											</thead>
											<tbody id="foods">
											</tbody>
										</table>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
	<!-- <script type="text/javascript" src="../../js/news.js"></script> -->
	<script src="../../js/Jquary/jquery-3.2.1.min.js"></script>
	<script src="../../js/Jquary/jquery.easyui.min.js"></script>
	<script src="../../js/bootstrap.min.js"></script> 
	<script type="text/javascript" src="../../js/logout.js"></script>
	<script type="text/javascript">
		sessionStorage.positionid = -1;
		$(document).ready(function(){
			$("#positions").on('click', '.naw',function(){
				var positionid = $(this).attr("id");
				var positionname = $(this).text();
				sessionStorage.positionid = positionid;
				seeMenus(positionid,positionname);
			});
			findHelpPosition();
			setInterval('findHelpPosition()',5000);//启动定时刷新
			$("#foods").on('click', '.recfood',function(){
				var orderid = $(this).attr("name");
				var r=confirm("处理后该记录将会消失，是否处理？");
				if (r==true){
					receiveOrder(orderid);
				}
			});
			$("#positions").on('click', '.handle',function(){
				var r=confirm("处理后该记录将会消失，是否处理？");
				if (r==true){
					var positionid = $(this).attr("name");
					closePsition(positionid);
				}
				event.stopPropagation();
			});
		})

		function findHelpPosition(){
				$.ajax({//查找需要帮助的位置
					type:"get",
					url:"/ldss/orders/showhelpposition",
					dataType:"json",
					async:false,
					success: function (data) {
						if(data.success){
							var data = data.data;
							$("#positions").empty();
								for(var i = 0; i < data.length; i++){//A22
									$("#positions").append(
										"<a id="+data[i].id+" class='naw list-group-item  list-group-item-danger'>"+data[i].positionName+
											"<button type='button' name='"+data[i].id+"' class='btn btn-danger btn-sm pull-right handle' style='margin-top: -5px'>"+
												"处理</button>"+
										"</a>"
										);
								}
							}else{
								alert(data.message);
							}
						}
					});
			}
			function seeMenus(positionid,positionname){//查看这个位置有什么需求
				$.ajax({
					type:"get",
					url:"/ldss/orders/showhelpmenu",
					async:false,
					data:{
						positionid:positionid
					},
					dataType:"json",
					success: function (data) {
						if(data.success){
							var data = data.data;
							$("#foods").empty();
							if(data.length>0){
								for(var i = 0; i < data.length; i++){
									$("#foods").append(
										"<tr>"+
										"<td>"+positionname+"</td>"+
										"<td>"+data[i].menuname+"</td>"+
										"<td>"+data[i].num+"</td>"+
										"<td>"+data[i].ordertype+"</td>"+
										"<td>"+ 
										"<button type='button' class='btn btn-primary recfood' name='"+data[i].id+"'>处理</button>"+
										"</td>"+
										"</tr>"
										);
								}
								$(this).removeClass("list-group-item-danger");
							}else{
								alert("该位置暂时没有需求")
							}
							
						}else{
							alert(data.message);
						}
					}
				});
			}
			function receiveOrder(orderid){//上菜
				$.ajax({
					type:"get",
					url:"/ldss/orders/receive",
					async:false,
					data:{
						orderid:orderid
					},
					dataType:"json",
					success: function (data) {
						var data = data;
						if(data.success){
							seeMenus(sessionStorage.positionid);
						}else{
							alert(data.message);
						}
					}
				});
			}
			function closePsition(positionid){//菜上全
				$.ajax({
					type:"get",
					url:"/ldss/orders/closepsition",
					async:false,
					data:{
						positionid:positionid
					},
					dataType:"json",
					success: function (data) {
						var data = data;
						if(data.success){
							alert(data.message);
							findHelpPosition();
						}else{
							alert(data.message);
						}
					}
				});
			}
		</script>
	</body>
	</html>